<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Relations\ValidateTrait;
use App\Models\Relations\CommentsTrait;
use App\Models\Relations\UserInfoTrait;
use App\Models\Relations\AttachmentTrait;
use App\Models\Relations\CategoryTrait;
use App\Models\Relations\CommonTrait;

/**
 * 课程
 * @author Joker
 *   name` VARCHAR(255) NOT NULL COMMENT '课程名称',
	cat_id int(10) NOT NULL COMMENT '分类编号',
	description text NOT NULL DEFAULT '' COMMENT '课程简介',
	notice text NOT NULL DEFAULT '' COMMENT '课程须知',
	thumb int(10) NOT NULL DEFAULT 0 COMMENT '课程封面图',
	`level` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '课程难易级别，0：初级；1：中级；2：高级',
	meta_value int(10) NOT NULL DEFAULT 0 COMMENT '时长，非视频不显示，默认为0',
	price MEDIUMINT(8) NOT NULL DEFAULT 0 COMMENT '价格 默认为0 免费',
	user_id   int(10) NOT NULL COMMENT '上传者编号',
	author_id	int(10) NOT NULL DEFAULT 0 COMMENT '讲师编号，对应用户，如果此为空则去user_id',
	`sort` int(10) DEFAULT NULL COMMENT '越大越靠前',
	views_num int(10) NOT NULL DEFAULT 0 COMMENT '浏览人数',
	studys_num int(10) NOT NULL DEFAULT 0 COMMENT '当前学习总人数',
	attention_num int(10) NOT NULL DEFAULT 0 COMMENT '当前课程关注总数',
	comments_num int(10) NOT NULL DEFAULT 0 COMMENT '当前课程评论数',
    `is_validate` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否通过审核 1:审核通过；0:未审核；2：审核不通过；默认 0',
	`validated_at` datetime DEFAULT NULL COMMENT '审核时间',
	`is_recommond` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否首页推荐 0 未推荐 1 已推荐',
	`education` varchar(50) DEFAULT NULL COMMENT '所属学院',
 */
class Teaches extends Model
{
    
    use SoftDeletes,ValidateTrait,CommentsTrait,UserInfoTrait,AttachmentTrait,CategoryTrait,CommonTrait;
    
    protected $table="teaches";
    
    protected $fillable = ['id','name','cat_id','description','notice','thumb','level','meta_value','price','user_id','is_hot',
        'sort','author_id','views_num','studys_num','attention_num','comments_num','is_validate','is_recommond','education'
    ];
    
    protected $dates = ['deleted_at','validated_at'];
    
    /**
     * 获取课程列表
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function chapters() {
        return $this->hasMany('App\Models\TeachesChapter','teaches_id','id');
    }
    
    /**
     * 新闻与标签关联表  一对多关联
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function tags()
    {
        return $this->hasMany('App\Models\TeachesTags','teaches_id','id');
    }

}
